package javaCode.chapter07.Homework.homework08;

//2、扩展前一个练习的BankAccount类 ，新类SavingsAccount 每个月都有利息产生
//(earnMonthlyInterest方法被调用)，并且有每三次免手续费的存款或取款。在earnMonthlyInterest方法中重置交易计数
public class SavingsAccount extends BankAccount{
    private int frequency = 3; //次数
    private double rate = 0.01; //利率

    public SavingsAccount(double balance) {
        super(balance);
    }

    //重置交易次数
    public void earnMonthlyInterest(){ //每个月初，我们统计上个月的利息，同时将frequency=3;
        this.frequency = 3;
        super.deposit(getBalance() * rate);
    }

    //存款
    public void deposit(double amount){
        if (frequency <=0 ) {
            super.deposit(amount - 1); //1 块转入银行账号
            return;
        }
        super.deposit(amount);
        frequency--;
    }

    //取款
    public void withdraw(double amount){
        if (frequency <= 0) {
            super.withdraw(amount + 1);
            return;
        }
        super.withdraw(amount);
        frequency--;
    }

    public int getFrequency() {
        return frequency;
    }

    public void setFrequency(int frequency) {
        this.frequency = frequency;
    }

    public double getRate() {
        return rate;
    }

    public void setRate(double rate) {
        this.rate = rate;
    }
}
